

#include "aki/jsbind.h"
#include "video_render.h"
#include "xcomponent_render_manager.h"

VideoRender::VideoRender(int32_t width, int32_t height, std::string pixFormat, std::string id)
: width_(width), height_(height), pixFormat_(pixFormat), id_(id)
{
}

int32_t VideoRender::Init()
{
    frameBuffer_ = std::make_unique<uint8_t []>(width_ * height_ * 3 / 2);
    return 0;
}

int32_t VideoRender::Render(uint8_t *yData, uint8_t *uData, uint8_t *vData, int32_t width, int32_t height)
{
    std::shared_ptr<I420Render> render = XcomponentRendersManager::GetInstance().GetRender(id_);
    if (render != nullptr) {
        return render->Render(yData, uData, vData, width, height);
    }
    return 0;
}

int32_t VideoRender::Width() const
{
    return width_;
}

int32_t VideoRender::Height() const
{
    return height_;
}

std::string VideoRender::PixFormat() const
{
    return pixFormat_;
}

uint8_t *VideoRender::FrameBuffer()
{
    if (frameBuffer_ != nullptr) {
        return frameBuffer_.get();
    }
    return nullptr;
}

